checkLogin();

// 非法文件名正则
window.nameReg = /[\/\?\*\\:;"'<>]|\.{2,}|^\.$|\.$/;
// 排序规则
window.__sortOrder = localStorage.getItem("__sortOrder") || "asc";
// 排序字段
window.__sortColumn = localStorage.getItem("__sortColumn") || "filename";
// 当前路径
window.__path = "/";
// 皮肤
window.__skin = window.__tempSkin = localStorage.getItem('__skin') || 'default';



$('body').removeAttr('class').addClass(window.__skin);


// 鼠标悬停，添加class，移出时去除class
function show111(selector, className){
	$(selector).mouseover(function(){
		var me = $(this);

		if(me.data("showTimer")){
			clearTimeout(me.data("showTimer"));
			me.removeData("showTimer");
		}

		me.addClass(className);
	}).mouseout(function(){
		var me = $(this);

		if(me.data("showTimer")){
			clearTimeout(me.data("showTimer"));
		}

		var timer = setTimeout(function(){
			me.removeClass(className);
			me.removeData("showTimer");
		}, 400);
		me.data("showTimer", timer);
	});
}

show111("#dropdown", "hover");
show111("#more-btn", "hover");

function getSelectedFiles(){
	var selected = $("#file-table tbody .checkbx.checked");

	return selected.parents("tr");
}

// 删除文件
function deleteFile(fileids, callback){
	$.ajax({
		url: "/pan/userfile/deleteFile",
		type: 'get',
		data: {userfileId: fileids},
		dataType: "json",
		timeout: 10000,
		success: function(data){
			if(data.statusCode == 200){
				if(typeof(callback) == "function"){
					callback();
				}
			}
		},
		error: function(){
		}
	});
}

// 还原文件
function restoreFile(fileids, callback){
	$.ajax({
		url: "/pan/userfile/restoreFile",
		data: {userfileId: fileids},
		dataType: "json",
		timeout: 10000,
		success: function(data){
			if(data.statusCode == 200){
				if(typeof(callback) == "function"){
					callback();
				}
			}
		},
		error: function(){
		}
	});
}

// 获取当前路径
function getCurrentPath(){
	return decodeURIComponent(window.__path);
}

function updateFileCount(count){
	count = (count && !isNaN(count)) ? parseInt(count) : 0;
	var filecount = $(".path-box .file-count");
	filecount.html("已加载" + count + "个文件");
}

// 获取所有文件
function getAllFiles(path, order, callback){}


// 在pathbox显示当前路径
function updatePathBox(){
	var currentPath = getCurrentPath();
	var dirs = currentPath.split("/");
	var path = $("#path").empty();

	var tmp = [];
	for (var i = 0; i < dirs.length; i++) {
		if(dirs[i]){
			tmp.push(dirs[i]);
		}
	}
	dirs = tmp;

	if(dirs.length > 0){
		$("#path-up").addClass("show");
		path.append('<a href="#' + window.__hash.action +'?path=/" path="/">全部文件</a>');
	}else{
		path.append('<span class="active">全部文件</span>');
		$("#path-up").removeClass("show");
		return;
	}

	// 用来拼接位置URL
	var pathURL = "";
	for (var i = 0, j = dirs.length - 1; i < j; i++) {
		path/*.append(a)*/.append(" &gt; ");
		var a = $("<a></a>");
		a.text(decodeURIComponent(dirs[i]));
		pathURL += "/" + dirs[i];
		a.attr("href", "#" + window.__hash.action + "?path=" + encodeURIComponent(pathURL));
		a.attr("path", pathURL);
		path.append(a);
	}
	$("#path-up").attr("path", pathURL || "/");
	$("#path-up").attr("href", "#" + window.__hash.action + "?path=" + (encodeURIComponent(pathURL) || "%2F"));

	var span = $("<span></span>");
	span.text(decodeURIComponent(dirs[i])).addClass("active");
	path.append(" &gt; ").append(span);
}

// 列出文件
function listFiles(data){
	if(!data || data.length == 0){
		return;
	}

	var filelist = $("#file-table tbody");

	for (var i = 0; i < data.length; i++) {
		var f = data[i];

		// <tr data-fid="3" data-type="1">
		// 	<td data-field="filename">
		// 		<i class="fa checkbx"></i>
		// 		<div class="fileicon image"></div>
		// 		<a href="">5.jpg</a></td>
		// 	<td data-field="size">103.65K</td>
		// 	<td data-field="time">2016-04-07 04:15:20</td>
		// </tr>

		var tr = $('<tr></tr>');
		tr.attr("data-fid", f.userfileId);
		tr.attr("data-type", f.fileType ? "1" : "0");

		//文件名单元格
		var td = $('<td data-field="filename"></td>');
		td.append('<i class="fa checkbx"></i>');
		//文件图标
		var fi = $('<div class="fileicon"></div>');
		fi.addClass(getFileIcon(f.fileName));
		td.append(fi);
		//文件链接
		var path = getCurrentPath().replace(/\/+$/, "") + "/" + f.fileName;
		var a = $('<a></a>');
		if(!f.fileType && window.__hash.action != "recycle"){
			a.attr("href", "#" + window.__hash.action + "?path=" + encodeURIComponent(path));
		}else{
			a.attr("href", "/pan/userfile/download?userfileId=" + f.userfileId);
			a.attr('target', '_blank');
		}			
		a.attr("path", path);
		a.text(f.fileName);
		td.append(a);
		tr.append(td);

		//文件大小单元格
		var td2 = $('<td data-field="size"></td>');
		td2.html(f.fileType ? smartSize(f.fileSize) : "-");
		tr.append(td2);

		//文件时间单元格
		var td3 = $('<td data-field="time"></td>');
		td3.html(new Date(f.uploadTime).format());
		tr.append(td3);
		filelist.append(tr);
	}
}

// 加载文件列表
function loadFiles(path, url, data){
	if(!defined(path)){
		throw new Error("missing arguments!");
	}

	path = decodeURIComponent(path);

	var lid = layer.load(1, {zIndex: -1});
	// 清空列表
	var tr = $('<tr><td style="padding-left:26px">加载中...</td></tr>');
	var table = $("#file-table tbody").empty().append(tr);

	data = data || {};

	if(window.__sortOrder == "desc"){
		data.sortOrder = "desc";
	}else{
		data.sortOrder = "asc";
	}
	if(!window.__sortColumn){
		data.sortColumn = "filename";
	}else{
		data.sortColumn = window.__sortColumn;
	}

	$.ajax({
		url: url,
		type: 'get',
		data: data,
		dataType: 'json',
		timeout: 10000,
		success: function(data){
			if(data.statusCode == 200){
				window.__path = path;
				updatePathBox();
				if(data.data && data.data.length > 0){
					updateFileCount(data.data.length);
					listFiles(data.data);
					tr.remove();
				}else{
					updateFileCount(0);
					tr.find("td").html('该目录下没有任何文件!');
				}
			}else{
				tr.find("td").html('<span style="color:red">服务器错误!</span>');
				updateFileCount(0);
			}
		},
		error: function(error){
			tr.find("td").html('<span style="color:red">加载失败!</span>');
			updateFileCount(data.length);
		},
		complete: function(){
			layer.close(lid);
		}
	});

}

// 加载普通文件
function loadCommonFiles(path){
	var data = {path: decodeURIComponent(path) || "/"};
	loadFiles(path, '/pan/userfile/getAllFiles', data);
}
// 加载图片
function loadCategories(category){
	if(!category) category = "images";

	var data = {category: category};
	loadFiles(getCurrentPath() || "/", '/pan/userfile/getByCategory', data);
}
// 回收站
function loadRecycle(){
	loadFiles(getCurrentPath() || "/", '/pan/userfile/getRecycle', {});
}

// 刷新文件列表
function refreshFileList(){
	$("#file-table th .checkbx").removeClass("checked");

	switch(window.__hash.action){
		case "all":
		loadCommonFiles(getCurrentPath() || "/");
		break;
		case "image":
		loadCategories("image");
		break;
		case "video":
		loadCategories("video");
		break;
		case "music":
		loadCategories("music");
		break;
		case "doc":
		loadCategories("doc");
		break;
		case "recycle":
		loadRecycle();
		break;
	}
}

// 新建文件夹
function mkdir(dirname, path, callback){
	path = path || getCurrentPath();

	var index = layer.load(1, {shade: [.3, '#000']});
	$.ajax({
		url: '/pan/userfile/mkdir',
		type: "get",
		data: {dirname: dirname, path: path},
		dataType: "json",
		success: function(data){
			if(data.statusCode == 200){
				if(typeof(callback) == "function"){
					callback(data.data);
				}
			}else{
				layer.alert('创建失败！', {icon: 6});
			}
		},
		complete: function(){
			layer.close(index);
		}
	});
}

// 关闭皮肤面板
function closeSkinPanel(){
	var box = $("#change-skin");
	var height = box.outerHeight();
	box.animate({"bottom": -height, "opacity": 0}, 350, function(){
		box.hide();
	});
};



// 剪切文件
function pasteFiles(files, target, option){
	// layer.alert(option + ': [' + files.map(k => k.path).join(',') + '] => ' + target);
	if(option=='cut'){
		console.log(files);
		for(var i=0,len=files.length;i<len;i++){
			var userfileId = files[i].fid;
			console.log(userfileId);
			$.ajax({
				url: '/pan/userfile/cutFile',
				data: {userfileId:userfileId,target:target},
				dataType: 'json',
				type: 'post', 
				success: function(data){
					if(data.statusCode==200){
					}
					window.__clipboard=null;
				},
				error: function(error){
				}
			});
		}
	}else if(option=='copy'){
		for(var i in files){
			var userFileId = files[i].fid;
			$.ajax({
				url:'/pan/userfile/copyFIle',
				data:{userfileId:userFileId,target:target},
				type:'post',
				success:function (e) {
					if(e.message=='success'){
					}
					window.__clipboard=null;
				},
				error: function(error){
				}
			})
		}
	}
	refreshFileList();
	
}

(function(){
	var username = getCookie('userName');
	if(!username) return;

	var head = getCookie('userPhoto') || '/image/head.jpg';

	$('#dropdown .user img,#dropdown .content .heading img').attr('src', head);
	$('#dropdown .user span,#dropdown .content .heading span').text(username);
})();













// 网页解析完成。。。。。
$(function(){
	// 加载解析hash
	$(window).trigger("hashchange");

	$('#file-table th[data-sortcolumn="' + window.__sortColumn + '"]').find(".sort").addClass("active");
	if(window.__sortOrder == "desc"){
		$("#file-table th").filter('[data-sortcolumn="' + window.__sortColumn + '"]').find(".sort").addClass("desc");
	}

	// 换肤面板初始化bottom，用来显示动画效果
	$("#change-skin").css("bottom", function(){
		return 0 - $(this).outerHeight();
	});

	// 设置文件列表最大高度为剩余的高度
	$("#file-table tbody").css("max-height", function(){
		var right = $(".main-right");
		// tbody到mai-right的距离
		var aa = $(this).offset().top - right.offset().top;
		// 高度 - 距离 = 剩余高度
		var bb = right.outerHeight() - aa;
		return bb;
	});


	$('#change-skin .skin-list [data-skin-name="' + window.__skin + '"]').addClass('active');
});









$(window).on("hashchange", function(event){
	if(event.originalEvent){
		event.originalEvent.preventDefault();
	}

	window.__hash = translateHash();

	var action = window.__hash.action;
	var params = window.__hash.params;

	if(!action){
		window.location.hash = "#all?path=/";
		return;
	}

	$(".main-left .types li").removeClass("active").filter('[data-action=' + action + ']').addClass("active");
	$("#file-table tbody").empty();
	$('#restore-btn').hide();
	$('#share-btn,#download-btn').show();
	if(action == "all"){
		if(__hash.params.path){
			window.__path = __hash.params.path;
		}
		$("#path-up,#path").removeClass("disabled");
	}else if(/^image|video|music|doc$/.test(action)){
		$("#path-up,#path").addClass("disabled");
	}else if(action == "recycle"){
		$('#restore-btn').show();
		$('#share-btn,#download-btn').hide();
	}
	refreshFileList();
});








// 按键绑定
$(window).keydown(function(e){
	var f = true;
	var code = e.keyCode;
	var ctrl = e.ctrlKey;

	// F2 重命名
	if(code == 113){
		f = false;
		$("#rename-btn").click();
	} // 复制，剪切   67: C  88: X
	else if((code == 67 || code == 88) && ctrl && window.__hash.action == 'all'){
		f = false;
		window.__clipboard = null;
		var selected = getSelectedFiles();
		if(selected.length == 0) return false;
		var files = [];

		selected.each(function(){
			var fl = {
				fid: $(this).data('fid'),
				path: $(this).find('[data-field="filename"] a').attr('path')
			};
			files.push(fl);
		});

		window.__clipboard = {source: getCurrentPath(),files: files, option: (code == 67) ? 'copy' : 'cut'};

		var c = '操作成功';
		if(window.__clipboard.option == 'cut'){
			c = '剪切成功，请使用“Ctrl + V”粘贴';
		}else{
			c = '复制成功，请使用“Ctrl + V”粘贴';
		}

		layer.msg(c);

		console.log(window.__clipboard);
	} // 粘贴  86: V
	else if(code == 86 && ctrl && window.__hash.action == 'all'){
		if(!window.__clipboard) return;

		// 合理性判断
		var fff = true;
		var board = window.__clipboard;

		if(board.source == getCurrentPath()){
			fff = false;
		}

		var cpath = getCurrentPath().replace(/\/+$/, '');


		for (var i = 0; i < board.files.length; i++) {
			if(cpath == board.files[i].path){
				fff = false;
				layer.msg('不能复制或剪切文件夹到自己本身');
				break;
			}
		}

		if(fff){
			pasteFiles(board.files, getCurrentPath(), board.option);
		}
	}



	// return f;
});













// 左侧导航点全部文件，回到首页
$('.main-left .types li').click(function(e){
	if($(this).is('[data-action="all"]') && window.__hash.action == "all"){
		refreshFileList();
		return false;
	}

	window.__path = "/";
});


// 还原文件
$("#restore-btn").click(function(){
	var selected = getSelectedFiles();

	if(!selected) return;

	selected.each(function(){
		var me = $(this);
		restoreFile(parseInt($(this).attr("data-fid")), function(){
			me.fadeOut(function(){
				me.remove();
			});
		});
	});
});


// 换肤按钮，打开换肤面板
$("#skin-btn").click(function(){
	$("#change-skin").animate({"bottom": 0, "opacity": 1.0}, 350).show();
});
// 关闭换肤面板
$("#change-skin").find(".skin-close,.cancel").click(function(){
	var currentSkin = window.__tempSkin;

	if(window.__skin != window.__tempSkin){
		var index = layer.confirm('要保存修改吗？', function(){
			window.__skin = window.__tempSkin;
			localStorage.setItem('__skin', window.__skin);
			closeSkinPanel();
			layer.close(index);
		},function(){
			var oldSkin = $('#change-skin .skin-list [data-skin-name="' + window.__skin + '"]');
			var thumb = oldSkin.data('skin-thumb');
			$('#change-skin .skin-screenshot img').attr('src', thumb);
			oldSkin.addClass('active').siblings().removeClass('active');
			$('body').removeClass(window.__tempSkin).addClass(window.__skin);
			window.__tempSkin = window.__skin;
			closeSkinPanel();
			layer.close(index);
		});
	}else{
		closeSkinPanel();
		layer.close(index);
	}
});
// 确定修改
$("#change-skin").find(".ok").click(function(){
	window.__skin = window.__tempSkin;
	localStorage.setItem('__skin', window.__skin);
	closeSkinPanel();
});
// 切换皮肤
$("#change-skin .skin-list").on("click", 'li', function(){
	$("#change-skin .skin-screenshot img").attr('src', $(this).data('skin-thumb'));
	$('body').removeClass(window.__tempSkin).addClass($(this).data('skin-name'));
	$(this).addClass('active').siblings().removeClass('active');
	window.__tempSkin = $(this).data('skin-name');
});

// 文件列表点击
// $('#file-table').on("click", 'td[data-field="filename"] a', function(e){
// 	e.stopPropagation();
// 	return;
// });


// 路径框点击
// $('.path-box').on("click", 'a', function(e){
// 	var tr = $(this).parents("tr");

// 	if(tr.data("type") == '0'){
// 	}
// });

// 删除文件
$("#delete-btn").click(function(){
	var selected = getSelectedFiles();

	if(!selected) return;

	// if(!confirm("确定删除选择的文件？删除后可以在回收站找回哦")){
	// 	return;
	// }

	layer.confirm('确定删除选择的文件？删除后可以在回收站找回哦！',function(index){
		layer.close(index);
		selected.each(function(){
			var me = $(this);
			deleteFile(parseInt($(this).attr("data-fid")), function(){
				me.fadeOut(function(){
					me.remove();
				});
			});
		});
	});
	
});

// 还原文件
$("#restore-btn").click(function(){
	var selected = getSelectedFiles();

	if(!selected) return;

	selected.each(function(){
		var me = $(this);
		restoreFile(parseInt($(this).attr("data-fid")), function(){
			me.fadeOut(function(){
				me.remove();
			});
		});
	});
});

// 重命名
$('#rename-btn,[data-target="#rename-btn"]').click(function(){
	var selected = getSelectedFiles();
	if(selected.length == 0 || selected.length > 1) return;

	var oldName = selected.find('[data-field="filename"] a').text();
	layer.prompt({formType: 0,title: '请输入新名称', value: oldName}, function(value, index, elem){
		layer.close(index);
		value = $.trim(value);
		if(window.nameReg.test(value)){
			layer.alert('文件名不合法！', {icon: 2});
			return;
		}

		var loader = layer.load(1, {zIndex: -1});
		$.ajax({
			url: '/pan/userfile/rename',
			type: 'get',
			data: {userfileId: selected.data('fid'), newName: value},
			dataType: 'json',
			setTimeout: 10000,
			success: function(data){
				if(data.statusCode == 200){
					// 更新名称
					var a = selected.find('[data-field="filename"] a').text(value);
					if(selected.data('type') == '0'){
						var href = '';
						if(getCurrentPath().endsWith('/')){
							href = getCurrentPath() + value;
						}else{
							href = getCurrentPath() + '/' + value;
						}

						// 更新连接地址
						a.attr('href', '#all?path=' + encodeURIComponent(href));
					}
					a.attr('path', href);
					selected.find('.fileicon').attr('class', 'fileicon').addClass(getFileIcon(value));

					// refreshFileList();
				}else{
					layer.alert('重命名失败！', {icon: 2});
				}
			},
			error: function(){
				layer.alert('重命名失败！', {icon: 2});
			},
			complete: function(){
				layer.close(loader);
			}
		});
	});
});


// 创建文件夹
$("#mkdir-btn").click(function(){
	layer.prompt({
		formType: 0,
		value: '',
		title: '请输入文件夹名称'
	}, function(value, index, elem){
		layer.close(index);
		value = $.trim(value);
		if(!value){
			return;
		}
		if(window.nameReg.test(value)){
			layer.alert('文件名不合法！', {icon: 2});
			return;
		}
		mkdir(value, getCurrentPath(), function(data){
			refreshFileList();
		});
		
	});
});

// 清除搜索文本按钮
$("#clearsearch").click(function(){
	$("#searchtext").val("").focus();
	$(this).hide();
});

// 搜索时判断显示清除按钮
$("#searchtext").on("input", function(){
	if($(this).val()){
		$("#clearsearch").css("display", "initial");
	}else{
		$("#clearsearch").hide();
	}
});

//搜索
$("#search_form").submit(function(e){
	e.preventDefault();
	var searchtext = $("#searchtext").val();

	if(!searchtext) return;

	var loading = layer.load(1);
	var isSuccess = true;
	$.ajax({
		url: '/pan/userfile/search',
		type: 'get',
		data: {filename: searchtext},
		dataType: 'json',
		success: function(data){
			if(data.statusCode == 200){
				$("#file-table tbody").empty();
				listFiles(data.data);
			}else{
				isSuccess = false;
			}
		},
		error: function(error){
			isSuccess = false;
		},
		complete: function(){
			layer.close(loading);
			if(!isSuccess){
				layer.alert('搜索文件失败', {shade: [.3, '#000']});
			}
		}
	});
});

// 选择单个文件
$("#file-table tbody").on("click", ".checkbx", function(e){
	e.stopPropagation();

	$(this).toggleClass("checked");

	var all = $("#file-table tbody tr");
	var selected = getSelectedFiles();

	if(selected.length == 0){
		$("#file-option").hide();
		$("#file-table th .checkbx").removeClass("checked");
		return;
	}

	if(selected.length == all.length){
		$("#file-table th .checkbx").addClass("checked");
	}else{
		$("#file-table th .checkbx").removeClass("checked");
	}

	// 选择了多个文件，不允许重命名
	if(selected.length > 1){
		$('#rename-btn,[data-target="#rename-btn"]').addClass("disabled");
	}else{
		$('#rename-btn,[data-target="#rename-btn"]').removeClass("disabled");
	}

	$("#file-option").css("display", "inline-block");
});

$("#file-table tbody").on("click", "td", function(e){
	if(e.target != this){
		return;
	}

	$(this).parent("tr").find(".checkbx").click();
});

// 全选
$("#file-table th .checkbx").click(function(e){
	e.preventDefault();
	e.stopPropagation();

	var checkbx = $("#file-table tbody .checkbx");
	var notSelected = checkbx.not(".checked");

	//没有任何元素没被选中（所有元素都被选中了），那就要取消全选啦！
	if(notSelected.length == 0){
		$(this).removeClass("checked");
		checkbx.filter(".checked").click();
	}else{
		$(this).addClass("checked");
		notSelected.click();
	}
});

// 排序
$("#file-table th").click(function(){
	var sort = $(this).find(".sort");

	sort.toggleClass("desc").addClass("active");
	$(this).siblings().find(".sort").removeClass("active");
	var isDesc = sort.is(".desc");

	window.__sortColumn = $(this).attr("data-sortcolumn");
	// 降序
	if(isDesc){
		window.__sortOrder = "desc";
	}else{ // 升序
		window.__sortOrder = "asc";
	}
	localStorage.setItem("__sortOrder", window.__sortOrder);
	localStorage.setItem("__sortColumn", window.__sortColumn);

	refreshFileList();
});

// 客户端
$("#app-btn").click(function(){
	layer.alert('功能正在努力开发中，敬请期待！', {icon: 6});
});

// 反馈
$("#feed-btn").click(function(){
	layer.prompt({
		formType: 2,
		value: '',
		title: '请输入反馈内容',
		// area: ['800px', '350px'] //自定义文本域宽高
	}, function(value, index, elem){
		layer.close(index);

		//////////////////////////////////////////////////////
		$.ajax({
			url: '/pan/message/insertMessage',
			data: {messageContent:value},
			dataType: 'json',
			type: 'post', 
			success: function(data){
				if(data.statusCode==200){
					layer.alert("亲反馈成功！！！感谢您对我们的支持",{icon:6});

				}
			},
			error: function(error){

			}
		});
		/////////////////////////////////////////////////////

	});
});

// 下载
$('#download-btn').click(function(){
	var selected = getSelectedFiles();

	if(selected.length == 0){
		return;
	}

	var fids = [];
	selected.each(function(){
		fids.push($(this).data('fid'));
	});
	var a = $('<a style="display: none">download</a>');
	a.attr('href', '/pan/userfile/download?userfileId=' + fids.join(','));
	a.on('click', function(){
		a.remove();
	});
	$('body').append(a);
	a[0].click();
});


$('#off-download-btn').click(function(){
	var index = layer.open({
		type: 1,
		shade: .3,
		closeBtn: 1,
		area: ['400px', '300px'],
		title: '新建离线下载',
		content: $('#offline-box').show()
	});
	$('#offline-box').data('layer-index', index);
});

$('#add-offline-btn').click(function(){
	var filename = $('#offline-filename').val();
	var url = $('#offline-url').val();

	if(!url){
		layer.alert('链接地址不能为空', {icon: 0});
		$('#offline-url').focus();
		return;
	}
	if(!filename){
		layer.alert('文件名不能为空', {icon: 0});
		$('#offline-filename').focus();
		return;
	}

	if(nameReg.test(filename)){
		layer.alert('文件名不合法', {icon: 0});
		$('#offline-filename').focus().val('');
		return;
	}

	var index = layer.msg('正在添加...', {offset: '60px'});
	$.ajax({
		url: '/pan/offline/addOfflineTask',
		type: 'post',
		data: {filename: filename, url: url},
		dataType: 'json',
		success: function(data){
			layer.close(index);
			if(data.statusCode == 200){
				layer.alert('下载完成', {icon: 1});
			}else if(data.statusCode == 201){
				layer.alert('创建离线下载成功，<br>请稍后在“所有文件”中查看。', {icon: 1});
			}else{
				layer.alert('创建下载任务失败', 2);
			}
		},
		error: function(){
			layer.alert('连接服务器失败');
		},
		complete: function(){
			layer.close($('#offline-box').data('layer-index'));
		}
	});
});

$('#logout').click(function(){
	$.ajax({
		url: '/pan/logout',
		type: 'post',
		dataType: 'json',
		success: function(data){
			var x = (new Date()).getTime() - 99999;
			document.cookie = 'userId=;expires=' + x;
			document.cookie = 'userName=;expires=' + x;
			document.cookie = 'userPhoto=;expires=' + x;
			document.cookie = 'userEmail=;expires=' + x;
			window.location.href = '/';
		}
	});
});